#ifndef DICOMPRINTTHREAD_H
#define DICOMPRINTTHREAD_H

#include <QThread>
#include "global.h"
class DVInterface;
class DVPSStoredPrint;
class QPrinter;

class DicomPrintThread : public QThread
{
    Q_OBJECT
public:
    explicit DicomPrintThread(const QString &printerAE, QMutex *mutex, QObject *parent = 0);
    ~DicomPrintThread();

    void run();
    void setPrintRules(const QList<PrintRule*> rules, const PrintFormat &pformat,
                       const FilmPaperMap &fpmap) {
        ruleList = rules;
        format = pformat;
        paperMap = fpmap;
    }

    static bool dcm2bmp(QPixmap &pixmap, const char *file);

signals:
    void threadMsg(int level, const QString &msg);

public slots:

private:
    bool spoolStoredPrintFile(const QString &spfile);
    void spoolJobList();
    void updateJobList();
    void setCurrentRule();
    bool printFilm(DVPSStoredPrint &stprint, const QList<QPixmap> &pixmaps);
    void setImageArea(QPainter *painter, int dpi, bool portrait, const QString &filmSize);
    void setPaperSize(QPrinter *printer, const QString &film);
    void drawPageHeaders(QPainter *painter);
    void drawImageGrids(QPainter *painter, int dpi, int column, int row, QList<QRect> &rects);
    void drawImages(QPainter *painter, const QList<QRect> &rects, const QList<QPixmap> &pixmaps);

    QString aetitle;
    DVInterface *dvi;
    QList<PrintRule*> ruleList;
    PrintRule *currentRule;
    PrintFormat format;
    FilmPaperMap paperMap;
    QMutex *_mutex;

    class PrintJob
    {
    public:
      PrintJob() : numberOfCopies(1){}
      ~PrintJob() { }

      QString studyUID;
      QString seriesUID;
      QString instanceUID;
      QString storedPrintFilename;
      QString mediumType;
      QString filmDestination;
      QString filmSessionLabel;
      QString printPriority;
      QString ownerID;
      unsigned long numberOfCopies;
    };

    QList<PrintJob*> printJobList;

};

#endif // DICOMPRINTTHREAD_H
